package cn.z2huo.usercenter.management.app.csv;

import cn.hutool.core.text.csv.CsvWriteConfig;
import cn.hutool.core.text.csv.CsvWriter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *
 * @author z2huo
 */
@Slf4j
class CsvTestDataGenerator {

    /**
     * 测试数据生成路径
     */
    public static final String DATA_PATH = "user-center/user-management/user-management-app/src/main/resources/csv/problem/NO_0003/";

    // 测试数据生成数量
    public static final int TEST_DATA_SIZE = 10_000;
//    public static final int TEST_DATA_SIZE = 100_000;
//    public static final int TEST_DATA_SIZE = 1_000_000;
//    public static final int TEST_DATA_SIZE = 5_000_000;

    public static void main(String[] args) throws IOException {

        Solution solution = new Solution();

        List<Data> list = new ArrayList<>(TEST_DATA_SIZE);
        for (int i = 0; i < TEST_DATA_SIZE; i++) {
            String string = RandomStringUtils.randomAlphabetic(4, 32).toLowerCase();
            list.add(new Data(string, solution.lengthOfLongestSubstring4(string)));
        }

        CsvWriteConfig csvWriteConfig = CsvWriteConfig.defaultConfig();
//        csvWriteConfig.setHeaderAlias(Map.of("string", ""));

//        File file = new File(DATA_PATH + "test_data_" + TEST_DATA_SIZE + ".csv");
        File file = ResourceUtils.getFile(DATA_PATH + "test_data_" + TEST_DATA_SIZE + ".csv");
//        File file = ResourceUtils.getFile("classpath:csv/problem/NO_0003/test_data_" + TEST_DATA_SIZE + ".csv");

        try (FileWriter fileWriter = new FileWriter(file);
             CsvWriter csvWriter = new CsvWriter(fileWriter, csvWriteConfig)) {

            csvWriter.writeBeans(list);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @lombok.Data
    @Accessors(chain = true)
    @NoArgsConstructor
    @AllArgsConstructor
    static class Data {

        private String string;

        private int expect;
    }

}
